#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+7;
int T,n,m,l,vlim,p[N];
struct car{
    int s,v,a;
}c[N];
pii s[N];

bool check(int d,car c){ //legal
    //cerr<<"check: "<<(d-c.s)<<' '<<c.v<<' '<<c.a<<' ';//
    bool tmp=2ll*c.a*(d-c.s)<=(ll)vlim*vlim-(ll)c.v*c.v;
    if(c.a>0) tmp|=(d<c.s);
    //cerr<<(tmp?"legal":"illegal")<<endl;//
    return tmp;
}

int query1(car c){ //first illegal
    int l=1,r=m;
    while(l<r){
        int mid=(l+r)>>1;
        //cerr<<"query1 "<<l<<' '<<r<<' '<<mid<<endl;//
        if(check(p[mid],c)) l=mid+1;
        else r=mid;
    }
    return l;
}

int query2(car c){ //first legal
    int l=1,r=m;
    while(l<r){
        int mid=(l+r)>>1;
        //cerr<<"query2 "<<l<<' '<<r<<' '<<mid<<endl;//
        if(check(p[mid],c)) r=mid;
        else l=mid+1;
    }
    return l;
}

pii getcommon(pii x,pii y){
    pair<int,int> res={max(x.first,y.first),min(x.second,y.second)};
    if(res.first>res.second) return {-1,-1};
    return res;
}

int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    scanf("%d",&T);
    while(T--){
        scanf("%d%d%d%d",&n,&m,&l,&vlim);
        for(int i=1;i<=n;i++) scanf("%d%d%d",&c[i].s,&c[i].v,&c[i].a);
        for(int i=1;i<=m;i++) scanf("%d",p+i);
        sort(p+1,p+m+1);
        int cnt=0,cntc=0;
        for(int i=1;i<=n;i++){
            s[i]={1,m};
            int p0=lower_bound(p+1,p+m+1,c[i].s)-p; //first meet p
            //cerr<<"query p0: "<<c[i].s<<' '<<p0<<endl;//
            if(c[i].a==0){
                //cerr<<i<<" type0 "<<p0<<endl;//
                if(c[i].v>vlim){
                    if(p0<=m){
                        cnt++;
                        s[i]={p0,m};
                    }
                }
            }
            else if(c[i].a>0){
                int q=query1(c[i]);
                //cerr<<i<<" type1 "<<p0<<' '<<q<<endl;//
                if(max(p0,q)<=m){
                    cnt++;
                    s[i]={max(p0,q),m};
                }
            }
            else{
                int q=query2(c[i]);
                //cerr<<i<<" type2 "<<p0<<' '<<q<<endl;//
                if(p0<q){
                    cnt++;
                    s[i]={p0,q-1};
                }
            }
        }
        sort(s+1,s+n+1);
        pii tmp={-1,-1};
        for(int i=1;i<=n;i++){
            //cerr<<s[i].first<<' '<<s[i].second<<endl;//
            tmp=getcommon(tmp,s[i]);
            if(tmp.first==-1){
                tmp=s[i];
                cntc++;
            }
            //cerr<<"new: "<<tmp.first<<' '<<tmp.second<<' '<<cntc<<endl;//
        }
        //cerr<<"res: "<<n<<' '<<cnt<<' '<<cntc<<' '<<n-cntc<<endl;//
        printf("%d %d\n",cnt,n-cntc);
        //cerr<<endl;//
    }
    return 0;
}
